{template 'common/header'}
<style type="text/css">
.home-box div  center{
	color:#666666;
	font-size:10px;
	margin-top:15px;
}
.home-box{overflow:hidden; margin:10px 5px;float:left}
.home-box > a{float:left; display:block; width:{php echo 100/4;}%; text-align:center;  text-decoration:none;color:white;}
.home-box > a div{margin:0 14px; padding:12px 0;border-radius:5px;width: 40px;height:40px;}
.home-box > a div i{display:block; font-size:18px;}
</style>
<ul class="nav nav-tabs">
	<li {if $op == 'add'}class="active"{/if}><a href="{php echo $this->createWebUrl('nav', array('op' => 'add'))}">添加菜单</a></li>
	<li {if $op == 'list'}class="active"{/if}><a href="{php echo $this->createWebUrl('nav', array('op' => 'list'))}">管理菜单</a></li>
</ul>
<div class="main">
	<div class="category">
		<form action="" method="post" onsubmit="return formcheck(this)">
		<table class="table table-hover">
			<thead>
				<tr>
					<th style="width:10px;"></th>
					<th style="width:40px;">显示顺序</th>
					<th style="width:120px;">菜单名称</th>
					<th style="width:40%;">操作</th>
				</tr>
			</thead>
			<tbody>
			{loop $list $key $row}
				
				<tr>
					<td>
						
						<a href="javascript:;">
							<i class="icon-chevron-down"></i>
						</a>
						
					</td>
					<td>
						<input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}">
					</td>
					<td>
						<div class="type-parent">{$row['title']}&nbsp;&nbsp;
							<a href="{php echo $this->createWebUrl('nav', array('pcate' => $row['id'], 'op' => 'add'))}">
								<i class="glyphicon glyphicon-plus-sign"></i> 添加菜单
							</a>&nbsp;&nbsp;&nbsp;
							
							
						</div>
					</td>
					<td>
						<label data="{$row['isshow']}" class='label label-default {if $row['isshow']==1}label-info{else}{/if}' onclick="setProperty(this,{$row['id']},'isshow')">{if $row['isshow']==1}首页推荐{else}首页关闭{/if}</label>
						<a href="{php echo $this->createWebUrl('nav', array('op' => 'add', 'id'=>$row['id']))}" title="编辑" class="btn btn-default btn-sm">
						<i class="fa fa-edit" data-toggle="tooltip" data-placement="top"></i>编辑</a>
						{if $key >2}
						<a onclick="del({$row['id']})"  class="btn btn-default btn-sm" title="删除"><i class="fa fa-times"></i>删除</a>
						{/if}
						 <input type="checkbox" value="1"{if intval($row[status])==1} checked="checked"{/if} data="{$row[id]}"/>
						
					</td>
				</tr>
				
				{loop $children[$row['id']] $k $item}
				<tr>
					<td></td>
					<td><input type="text" class="form-control" name="displayorder[{$item['id']}]" value="{$item['displayorder']}"></td>
					<td>
						
														
									{if $item['thumb']}
									<img src="{php echo tomedia($item['thumb'])}" alt="..." class="img-thumbnail" style="width:60px;height:60px;">
									{else}
									<div class="home-box">
									<a href="#">

									<div style='background:{$item['bgcolor']}'>
									<i class="{$item['icon']}"></i>
									</div>
									</a>
									</div>
									{/if}
									
								
							
						<div style="float:left;line-height:60px;">{$item['title']}&nbsp;&nbsp;	
						</div>
					</td>
					<td>
						<label data="{$item['isshow']}" class='label label-default {if $item['isshow']==1}label-info{else}{/if}' onclick="setProperty(this,{$item['id']},'isshow')">{if $item['isshow']==1}首页推荐{else}首页关闭{/if}</label>
						<a href="{php echo $this->createWebUrl('nav', array('op' => 'add', 'id'=>$item['id']))}" title="编辑" class="btn btn-default btn-sm">
						<i class="fa fa-edit" data-toggle="tooltip" data-placement="top"></i>编辑</a>
						{if $k>5}
						<a onclick="del({$item['id']})"  class="btn btn-default btn-sm" title="删除"><i class="fa fa-times"></i>删除</a>
						{/if}
						<a href="{php echo $this->createWebUrl('nav', array('op' => 'cover', 'id'=>$item['id']))}" title="设置入口" class="btn btn-default btn-sm">
						<i class="glyphicon glyphicon-plus" data-toggle="tooltip" data-placement="top"></i>设置入口</a>

						 <input type="checkbox" value="1"{if intval($item[status])==1} checked="checked"{/if} data="{$item[id]}"/>
					</td>
				</tr>
				{/loop}
			{/loop}
				<tr>
					<td></td>
					<td colspan="3">
						<input name="submit" type="submit" class="btn btn-primary" value="提交">
						<input type="hidden" name="token" value="{$_W['token']}" />
					</td>
				</tr>
			</tbody>
		</table>
		</form>
	</div>
</div>
<script type="text/javascript">
	require(['bootstrap.switch', 'util'], function($, u){
        $(function(){
            $(':checkbox').bootstrapSwitch();
            $(':checkbox').on('switchChange.bootstrapSwitch', function(e, state){
                $this = $(this);
                var id = $this.attr('data');
                var status = this.checked ? 1 : 0;
                // alert(hid);return false;
                $.post(location.href, {status: status, id: id}, function(resp){
                    if(resp != 'success') {
                        u.message('操作失败, 请稍后重试.')
                    }
                    {if !empty($module)}
                    else {
                        u.message('操作成功！');
                        window.setTimeout(function(){location.href = location.href;}, 800);
                    }
                    {/if}
                });
            });
            $('.btn').hover(function(){
                $(this).tooltip('show');
            },function(){
                $(this).tooltip('hide');
            });
        });
    });
function del(id){
  var id = id;
  var url = "{php echo $this->createWebUrl('nav',array('op' => 'delete'))}";
	            $.post(url,
	            {
	                id:id
	            },
	            function(msg){
	                    if (msg.status == 1) {
	                    	setTimeout(function(){
	                        	window.location.reload();
	                   		 },100);
	                    };
	                    
	            },
	            'json');
}
function setProperty(obj,id,type){
        $(obj).html($(obj).html() + "...");
        $.post("{php echo $this->createWebUrl('nav',array('op' => 'set'))}"
            ,{id:id,type:type, data: obj.getAttribute("data")}
            ,function(d){
                $(obj).html($(obj).html().replace("...",""));
                if(type=='isshow'){
                 $(obj).html( d.data=='1'?'首页推荐':'首页关闭');
                }
                $(obj).attr("data",d.data);
                if(d.result==1){
                    $(obj).toggleClass("label-info");
                }
            }
            ,"json"
        );
    }
</script>
{template 'common/footer'}